package com.weme.mine.view

import android.content.Context
import android.text.TextUtils
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.animation.Animation
import android.view.animation.ScaleAnimation
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.app.ActivityCompat.postponeEnterTransition
import androidx.core.app.ActivityCompat.startPostponedEnterTransition
import com.bumptech.glide.Glide
import com.weme.common.util.*
import com.weme.common.util.AppMkHelper.AGE
import com.weme.common.util.AppMkHelper.COUNTRY_CODE
import com.weme.common.util.AppMkHelper.NAME
import com.weme.mine.activity.UserInfoActivity
import com.weme.mine.databinding.ViewUserInfoMeBinding
import dev.kratos.api.user_server.v1.Users

class ViewUserInfoMe @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : ConstraintLayout(context, attrs, defStyleAttr) {
    private val mBinding = ViewUserInfoMeBinding.inflate(LayoutInflater.from(context), this, true)

    init {


        mBinding.tvName1.text = setNameAge(String.format(UserMKHelper.decodeString(NAME) + "," + UserMKHelper.decodeString(AGE)),6)

        val country = getCountryBean(UserMKHelper.decodeString(COUNTRY_CODE))
        country?.let {
            Glide.with(this).load(it.countryFlag).into(mBinding.imCountry1)
            mBinding.tvLanguage1.text = it.countryName
        }

    }

    fun setMode(user: Users) {

        if (!TextUtils.isEmpty(user.headPic)) {

            if(!TextUtils.isEmpty(UserMKHelper.decodeString(user.headPic))){
                mBinding.imHead1.loadImage(UserMKHelper.decodeString(UserMKHelper.decodeString(AppMkHelper.HEADPIC)))
            } else {
                mBinding.imHead1.loadImage(user.headPic)
            }

        }
        UserMKHelper.decodeString(NAME)
        mBinding.tvName1.text = String.format(user.nickname + "," + user.age)
        mBinding.tvContent1.text = user.intro
        mBinding.tvContent1.fadeIn()
        val country = getCountryBean(user.countryCode)
        country?.let {
            Glide.with(this).load(it.countryFlag).into(mBinding.imCountry1)
            mBinding.tvLanguage1.text = it.countryName
        }
    }
}